import type { ICategoryItem } from './typings/index';

const keys = ['label', 'value', 'category', 'dataType', 'statisticsType'];
/**
 * 列字段分类模板
 * @param {Array} list
 * @returns
 */
export const categoryListTemplate = (list:ICategoryItem[]) => `
export const fieldsCategoryList = [${list
  .map(
    (item) => {
      const fields = keys
        .map(key => {
          const value = item[key];
          if (value) {
            return `${key}: ${typeof value === 'string' ? `'${value}'` : value}`;
          }
          return null;
        })
        .filter(field => field !== null)
        .join(',\n      ');
      
      return `
    {
      ${fields}
    },`;
    }
  )
  .join('')}
]
  `;

/**
 * 列字段分类模板
 * @param {Array} list
 * @returns
 */
export const relationKeyMapTemplate = (object) => {
  return `
export const relationKeyMap = {
  ${Object.keys(object)
    .map(
      (key) => `
    '${key}': '${object[key]}',`
    )
    .join('\n')}
}
  `;
};
